home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
util
/
arc
/
VEC_3_231.lha
/
vec3231
/
docs
/
porting.doc
< prev
next >
Wrap
Text File
|
1993-12-06
|
9KB
|
224 lines
Here is the information you need if you are going to port vec to a new
system:
DO NOT MODIFY THE EXISTING SOURCE FILES UNLESS IT'S ABSOLUTELY NECESSARY!
Create a new header file `system.h' (replace `system' with the name of the
system you are porting vec to) and compile and link main.h, system.h, vec.h
and vdc.h using compiler option, which sets the symbol `MACH_HDR' to value
`"system.h"' (again `system' replaced).
system.h may define some or all of these macros:
SYSTEM
A string containing unique identifier for the system you are porting
to. This string will be appended to the version number. These
identifiers are already reserved:
"a" - Amiga version
"g" - generic version
"m" - MS-DOS version
"u" - UNIX version
Additional suffixes may be added to system string to identify some
subset of the generic system type. For example "a030" stands for
`Amiga with MC68030 or higher CPU'-version. If this macro is not
defined, the value "g" is used.
COPYRSIGN
A string containing the copyright sign. If the character set of your
system doesn't contain separate character for the copyright sign or
many different character sets may be used, then leave this undefined
and the default value "(c)" will be used.
BOLDON
A string containing the escape sequence which sets the console to
output boldface. If your console isn't capable to do it or it can't
be done simply by an escape sequence, leave this undefined or use
empty string.
BOLDOFF
A string containing an escape sequence for cancelling the effect of
BOLDON. If BOLDON is undefined or empty string, then leave this also
undefined or set this to empty string.
SMALLUSAGE
If this macro exists, then the usage displayed when illegal argument
line is typed will only list the available options. Otherwise it will
also give a short explanation for each option. This is intented to be
used when the normal forty-line usage is too big to fit on the
display.
DEFMETHOD
A character constant to identify the default encoding method. '0',
'1', '2', '3' or 'u'. If not set, '1' is used.
DEFWIDTH
The default line width - a numeric constant. If not set, the value 80
is used.
DEFWIDTHS
Same as above, but as a decimal string constant.
OK
Ok return code. Default 0.
WARN
Warning return code (wildcard patterns match nothing). Default 1.
ERROR
Error return code (some file not encoded/decoded properly). Default 2.
FAIL
Failure return code (operation unfinished). Default 3.
BUFSIZE
I/O buffer size in bytes. Two buffers of this size will be allocated.
The other one will actually be few bytes bigger. Default 32768.
VERSTRING
Unused string to be placed somewhere in the program binary. This is
for version information finding systems, which try to find some magic
code from the binary. If not defined, no string will be placed. You
can use these macros in your string:
ENAME Encoder name, currently "vec"
DNAME Decoder name, currently "vdc"
UENAME Upper case ENAME
UDNAME Upper case DNAME
RELEASE Release number string
VERSION Version number string
VERDATE Version date string
SYSTEM System string explained above
The full version number is `RELEASE "." VERSION SYSTEM'.
Besides these optional macros you will need one typedef, which is not
optional:
filehandle
The data type, which represents the lowest level file handle in your
system. No buffering is required. File functions below should refer
to filehandles of this type.
Then some functions are required. You may emulate these by macros in your
system.h or you may write them as functions to the new source file system.c:
void init(void)
You can put what ever initialization styff you might need in to this
function. Calling it will be the first thing vec does. If you don't
need any init function, make it an empty macro.
void cleanup(void)
Like init() but will be called before the program exits.
int interrupt(void)
If programs in your system have to check user interrupt (CTRL-C)
themselves, then you can put break check into this function. It
should return 0 if user has not attempted to interrupt the program
and non-zero if interrupt has been attempted. If you don't need this
function, make it a macro with value 0.
int failedopen(filehandle fh)
This should return a boolean indicating if the given filehandle is a
result of failed attempt to open a file.
filehandle getstdin(int bin)
This function should return the filehandle (defined above) referring
to standard input stream. Parameter is a boolean indicating if the
stream is wanted in binary mode. If programs in your system have no
standard input stream, then define this as a macro with a value,
which forces the failedopen()-function to return true if given to it
as parameter.
filehandle getstdout(int binary)
Same as above but for standard output.
filehandle openread(const char *name, int bin)
Function to open an existing file with given name for reading. Second
parameter indicates binary mode. The read pointer should be placed to
the beginning of the file.
filehandle openwrite(const char *name, int bin)
Create a new file and return a filehandle for writing to it. If file
with same name existed, it should be discarded.
filehandle openappend(const char *name, int bin)
Open existing file for writing. The write pointer at the end of the
file.
void closefile(filehandle fh)
Close an open file.
int readfile(filehandle fh, unsigned char *buf, int size)
Read at most <size> bytes from file <fh> to buffer <buf>. Return the
number of bytes actually read. This is allowed to read less than
<size> when the file still contains more data, but it is not allowed
to return zero or less unless the file is exhausted or there has been
an I/O error. Return value of less than zero is interpreted as an I/O
error.
int writefile(filehandle fh, const unsigned char *buf, int size);
Write at most <size> bytes from buffer <buf> to file <fh>. Return the
number of bytes actually written. This is allowed to write less than
<size>, but it is not allowed to return zero or less unless there has
been an I/O error.
void printerr(const char *string)
Print a string to standard error stream without buffering.
char *basename(const char *name)
Return pointer to the file name part of the given name, which may
contain path specification.
void setfilemode(const char *name, unsigned char *buf)
Set the file mode flags of the named file according to information in
buf. buf[2]&0x0F contains flag type and buf[4] and buf[5] contain the
actual flags. These are the type values:
0 - No flags
1 - buf[5] contains the Amiga flag byte
2 - buf[4]&0x01 is the high and buf[5] the low byte of UNIX
flags
3 - MS-DOS flags - details not defined yet
4 to 15 - not defined yet
Function should try to emulate any type with the flags of the current
system.
void getfilemode(const char *name, const unsigned char *buf, int uuencode)
If the third parameter is 0, then the file mode flags of the named
file should be stored to <buf> in any of the formats above. The
buffer is initialized to zeroes. If the third parameter is non-zero,
then the flags shoud be converted to unix flags and then written to
buf[0]...buf[2] as three octal digits. In this case the buffer is
initialized to "600".
char *firstmatch(const char *pattern)
char *nextmatch(void)
If the program should expand the wildcard patterns in your system
instead of the shell, then you may provide the expansion mechanism by
writing these functions. The wildcard pattern is given as parameter
to both functions. firstmatch() should return a string pointer to
the name of the first matching file or NULL if nothing matches().
The nextmatch is then called to get the subsequent file names until
it returns NULL. After the nextmatch has returned NULL, the
firstmatch() may be called again with a different pattern().
cleanup() function must do the necessary cleaning if the program
terminates before nextmatch() has returned NULL. If you don't want to
provide pattern matching mechanism, then define the firstmatch as
macro with pattern as it's value and nextmatch as macro with value
NULL.
int changedir(const char *directory_name)
Change the current work directory of the program. Should return zero
if failed and non-zero otherwise. Only needed when -D option is used.
If you don't want to implement this, then define it as a macro with
value 0.
See the existing system header and source files for examples.
Other sources don't include stdio.h, so if you need it, include it in your
system.h file.